package com.nineclock.approve.controller;

import com.nineclock.api.approve.ApproveDefinitionControllerApi;
import com.nineclock.approve.dto.ApproveDefinitionResultDto;
import com.nineclock.approve.dto.ApproveDefinitionSaveDto;
import com.nineclock.approve.dto.ApproveGroupDefinitionDto;
import com.nineclock.approve.service.ApproveDefinitionService;
import com.nineclock.common.entity.Result;
import com.nineclock.common.utils.UUIDUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping ("/approve")
public class ApproveDefinitionController implements ApproveDefinitionControllerApi{

    /**
     * 流程定义: 获取序列
     * @return
     */
    @Override
    @GetMapping ("/seq")
    public Result<String> seq() {
        return Result.success(UUIDUtils.getUUID());
    }

    @Autowired
    ApproveDefinitionService approveDefinitionService;
    /**
     *  审批流程管理
     * @return
     */
    @Override
    @GetMapping("/approveGroupDefinition")
    public Result <List<ApproveGroupDefinitionDto>> queryApproveGroupDefinition(){
        List<ApproveGroupDefinitionDto> approveGroupDefinitionDtos=approveDefinitionService.queryApproveGroupDefinition();
        return Result.success(approveGroupDefinitionDtos);
    }

    /**
     * 新增&修改
     * @param approveDefinitionSaveDto
     * @return
     */
    @Override
    @PostMapping("/approveDefinition")
    public Result saveApproveDefinition (@RequestBody ApproveDefinitionSaveDto approveDefinitionSaveDto){
        approveDefinitionService.saveAndModifyQuote(approveDefinitionSaveDto);
        return Result.success();
    }

    /**
     *  流程定义: 根据ID查询
     * @param id
     * @return
     */
    @Override
    @GetMapping("approveDefinition/{id}")
    public Result<ApproveDefinitionResultDto> queryById (@PathVariable("id") String id){
        ApproveDefinitionResultDto approveDefinitionResultDto=approveDefinitionService.queryById(id);
        return Result.success(approveDefinitionResultDto);
    }

}    